package cn.gailvlun.gll.presentation.emotion.edit

import android.app.Activity
import android.content.Intent
import cn.gailvlun.gll.R
import cn.gailvlun.gll.net.emotion.EmotionTag
import cn.gailvlun.gll.net.emotion.EmotionTagReq
import cn.gailvlun.gll.presentation.base.App
import cn.gailvlun.gll.presentation.base.BaseActivity
import com.github.markzhai.recyclerview.BaseViewAdapter


class SelectEmotionTagViewModel(val mActivity: BaseActivity) : BaseViewAdapter.Presenter {

    fun finishAndReturnResult(emotionTag: EmotionTag) {
        val intent = Intent()
        intent.putExtra(EMOTION_TAG_REQ, newRequest(emotionTag))
        mActivity.setResult(Activity.RESULT_OK, intent)
        mActivity.finish()
    }

    private fun newRequest(emotionTag: EmotionTag): EmotionTagReq {
        val req = EmotionTagReq()
        if (emotionTag.isUserCreated) {
            req.icon = emotionTag.icon
            req.title = emotionTag.title
            req.isUserCreated = true
        } else {
            req.id = emotionTag.id
            req.icon = emotionTag.icon
            req.title = emotionTag.title
            req.emotionState = emotionTag.emotionType
            req.isUserCreated = false
        }
        return req
    }

    fun getEmotionTagCount(emotionTag: EmotionTag): String {
        return if (emotionTag.isUserCreated) {
            "新情绪签"
        } else {
            if (emotionTag.emotionCount == 0) {
                ""
            } else {
                "${emotionTag.emotionCount}条情绪"
            }
        }
    }

    fun getClassifyLabel(classify: Int): String {
        val stringArray = App.getInstance().resources.getStringArray(R.array.emotion_select_tag_classify_label)
        return if (classify == 0) stringArray[0] else stringArray[1]
    }

}